<template>
  <div>
    <SearchList/>
      <div class="content" v-if="categories.length">
        <ul class="left">
          <li :class="{'active':activeIndex === index}" v-for="(item, index) in categories" :key="index" @click="activeIndex = index">{{item.cat_name}}</li>
        </ul>
        <div class="right">
          <img src="../../../static/image/titleImage.png" alt="">
          <ul>
            <li class="cate2" v-for="(item1, cate2) in categories[activeIndex].children" :key="cate2">
              <div class="title">/<span>{{item1.cat_name}}</span>/</div>
              <div class="layout">
                <div class="cate3" v-for="(item2, cate3) in item1.children" :key="cate3" @click="toSearchList(item2.cat_name)">
                  <img :src="item2.cat_icon" alt="">
                  <p>{{item2.cat_name}}</p>
                </div>
              </div>
            </li>
          </ul>
        </div>
      </div>
  </div>
</template>

<script>
import SearchList from '../../components/SearchList.vue'
export default {
  data () {
    return {
      activeIndex: 0,
      categories: []
    }
  },
  methods: {
    toSearchList (catName) {
      console.log(111)
      wx.navigateTo({
        url: '/pages/searchList/main?query=' + catName
      })
    },
    async getCategories () {
      this.categories = await this.$request({
        url: '/api/public/v1/categories'
      })
    }
  },
  created () {
    this.getCategories()
  },
  components: {
    SearchList
  }
}
</script>

<style lang="less" scoped>
.content {
  position: absolute;
  top: 100rpx;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;

  .left {
    overflow: auto;
    width: 198rpx;
    li {
      width: 100%;
      height: 100rpx;
      text-align: center;
      box-sizing: border-box;
      border-bottom: 1rpx solid #eee;
      font-size: 32rpx;
      line-height: 100rpx;
      background-color: #f4f4f4;
      position: relative;
      &.active {
        background-color: #ffffff;
        color: #eb4450;
        &::before {
          content: "";
          display: block;
          position: absolute;
          top: 20rpx;
          width: 8rpx;
          height: 60rpx;
          background-color: #eb4450;
        }
      }
    }
  }

  .right {
    flex: 1;
    height: 100%;
    padding: 20rpx 16rpx 0;
    overflow: auto;
    box-sizing: border-box;
    >img {
      width: 520rpx;
      height: 180rpx;
    }
    .cate2 {
      margin-bottom: 40rpx;
      .title {
        text-align: center;
        line-height: 110rpx;
        height: 110rpx;
        color: #e2e2e2;
        span {
          font-size: 40rpx;
          color: #333333;
        }
      }
      .layout {
        display: flex;
        flex-wrap: wrap;
      }
      .cate3 {
        display: flex;
        margin-bottom: 20rpx;
        flex-direction: column;
        align-items: center;
        >img {
          width: 120rpx;
          height: 120rpx;
        }
        p {
          font-size: 30rpx;
        }
        width: 33.33%;
      }
    }
  }
}
</style>